package jdbmaplite.util;

import java.io.Serializable;
import java.lang.reflect.Field;

public class MethodInfo implements Serializable {

	private static final long serialVersionUID = 1L;

	private String simpleMethodName = null;
	private Class<?> castType = null;
	private String[] parameterNames = null;

	// lazy data
	private Field[] castTypeDeclaredFields = null;

	/**
	 * Default constructor.
	 */
	public MethodInfo() {
		super();
	}

	/**
	 * Load CastType Declared Fields
	 * 
	 * @param isReloadFields
	 *            boolean
	 * @return Field[]
	 */
	public Field[] loadCastTypeDeclaredFields(boolean isReloadFields) {
		if (!isReloadFields && castTypeDeclaredFields != null) {
			return castTypeDeclaredFields;
		}
		// reload fields
		synchronized (this) {
			castTypeDeclaredFields = ClassUtils.getDeclaredFields(castType);
			return castTypeDeclaredFields;
		}
	}

	/**
	 * Get Simple Method Name
	 * 
	 * @return String
	 */
	public String getSimpleMethodName() {
		return simpleMethodName;
	}

	/**
	 * Set Simple Method Name
	 * 
	 * @param simpleMethodName
	 *            String
	 */
	public void setSimpleMethodName(String simpleMethodName) {
		this.simpleMethodName = simpleMethodName;
	}

	/**
	 * Get Cast Type
	 * 
	 * @return Class{T}
	 */
	@SuppressWarnings("unchecked")
	public <T> Class<T> getCastType() {
		return (Class<T>) castType;
	}

	/**
	 * Set Cast Type
	 * 
	 * @param castType
	 *            Class
	 */
	public void setCastType(Class<?> castType) {
		this.castType = castType;
	}

	/**
	 * Get Parameter Names
	 * 
	 * @return String[]
	 */
	public String[] getParameterNames() {
		return parameterNames;
	}

	/**
	 * Set Parameter Names
	 * 
	 * @param parameterNames
	 *            String[]
	 */
	public void setParameterNames(String[] parameterNames) {
		this.parameterNames = parameterNames;
	}

}